﻿using System;
using System.IO;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Utils;
using Utils.BreakHsl;
using Utils.EFInit;
using Utils.NLogHelper;

namespace ViewModel;

public class StartUp
{
    public static IServiceProvider? ServiceProvider { get; private set; }

    public static INlogHelper? LogHelper { get; set; } = null;
    public static IConfiguration? Configuration { get; private set; }

    public ServiceCollection Starter()
    {
        UserDbService.UserDbInit();
        RefalHsl.getMethod<HslCommunication.Authorization>();
        DispatcherHelper.Initialize();
        var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("AppSettings.json");
        Configuration = builder.Build();
        var serviceCollection = new ServiceCollection();
        SystemDependencyInjection.ConfigureServices(serviceCollection);
        WeakReferenceMessenger.Default.Register<IServiceProvider>(this, InitializeIoc);
        return serviceCollection;
    }

    private void InitializeIoc(object recipient, IServiceProvider message)
    {
        ServiceProvider = message;
    }
}